/************************************************************
 * Project Name		[Thinking_In_Java]
 * File Name     	[pkg_api_testing.Java_Lang_Math.java]
 * Creation Date 	[15-Jun-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_api_testing;

/**
 * java.lang.Math
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Java_Lang_Math {

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {

		// 常量
		System.out.println("PI " + Math.PI);
		System.out.println("E  " + Math.E);

		// 三角函数
		Math.sin(45);
		Math.cos(45);
		Math.tan(45);
		Math.atan(45);
		Math.atan2(45, 45);

		// 对数和指数
		Math.exp(10);
		Math.log(10);
		Math.log10(15);

		// 绝对值, 最大值和最小值
		System.out.println("取绝对值---" + Math.abs(-21.0));
		System.out.println("取最大值---" + Math.max(1, 3));
		System.out.println("取最小值---" + Math.min(1, 3));

		// 四舍五入
		double d1 = 3.4;
		double d2 = -3.4;
		System.out.println("四舍五入3.4---" + Math.round(d1));
		System.out.println("四舍五入-3.4---" + Math.round(d2));

		double d3 = 3.5;
		double d4 = -3.5;
		System.out.println("四舍五入3.5---" + Math.round(d3));
		System.out.println("四舍五入-3.5---" + Math.round(d4));

		// 向下取整
		double d5 = 3.4;
		double d6 = -3.4;
		System.out.println("向下取整3.4---" + Math.floor(d5));
		System.out.println("向下取整-3.4---" + Math.floor(d6));

		double d7 = 3.5;
		double d8 = -3.5;
		System.out.println("向下取整3.5---" + Math.floor(d7));
		System.out.println("向下取整-3.5---" + Math.floor(d8));

		// 向上取整
		double d9 = 3.4;
		double d10 = -3.4;
		System.out.println("向上取整3.4---" + Math.ceil(d9));
		System.out.println("向上取整-3.4---" + Math.ceil(d10));

		double d11 = 3.5;
		double d12 = -3.5;
		System.out.println("向上取整3.5---" + Math.ceil(d11));
		System.out.println("向上取整-3.5---" + Math.ceil(d12));

		// 幂运算和开平方
		System.out.println(Math.pow(2, 3));
		System.out.println(Math.sqrt(16));
	}

}
